* Dataset
use "Umfrage_Wave1_20160812_Anonym_def.dta"

* Variables (recoding)
recode env_gl (8=.)

recode commune (1=1) (2/3=0), gen(Glarus)
recode commune (2=1) (1=0) (3=0), gen(GlarusNord)
recode commune (3=1) (1/2=0), gen(GlarusSud)

recode exposition_LG (4=0) (1/3=1), gen(exposition_LG_d)
recode exposition2_LG (1/3=1) (4=0), gen(exposition2_LG_d)

recode hh_kids (2/3=1), gen(hh_kids_d)

gen notpart_land = part_land
recode notpart_land (5=0) (0=5) (1=4) (4=1) (3=2) (2=3)

gen notpart_na = part_na
recode notpart_na (10=0) (0=10) (1=9) (9=1) (2=8) (8=2) (3=7) (7=3) (4=6) (6=4)

gen pol_ideol_left =pol_ideol
gen pol_ideol_right= pol_ideol
recode pol_ideol_left (0/2=1) (3/10=0)
recode pol_ideol_right (0/7=0) (8/10=1)
gen pol_ideol_cat=1 if pol_ideol_left==1
replace pol_ideol_cat=3 if pol_ideol_right==1
recode pol_ideol_cat (.=2) if pol_ideol!=.

recode SozPressur_talk_opinion (1=1) (2/3=0), gen(SozPressur_talk_negative)
replace SozPressur_talk_negative=0 if SozPressur_talk==4

recode SozPressur_talk_opinion (1/2=0) (3=1), gen(SozPressur_talk_positive)

gen SozPressur_talk_cat = SozPressur_talk_opinion
replace SozPressur_talk_cat=0 if SozPressur_talk==4

label var gender "Female"
label define age_cat1 1 "18-25" 2 "26-35" 3 "36-45" 4 "46-55" 5 "56-65" 6 "66 or more"
label value age_cat age_cat1
label var income "Houshold Income"
label var education_rc "Education"
label var public_office_d "Public Office Holder"
label define commune_def 1 "Glarus" 2 "Glarus North" 3 "Glarus South" 4 "Extern"
label value commune commune_def
label var effic_int "Internal Efficacy"
labe var age "Age in years"
label var GlarusSud "Glarus South"
label var GlarusNord "Glarus North"
label var pol_int "Political interest"
label var knowledge_GL_rc "Political knowledge"
label var effic_int "Internal Efficacy"
label var exposition_LG_d "Disturbed by being observed"
label var exposition2_LG_d "Observing others"
label define pol_ideol_cat 1 "Left ideology" 2 "Moderate ideology" 3 "Right ideology", modify
label value pol_ideol_cat pol_ideol_cat
label var party_member "Party Member"
label var env_gl "Social Network"

drop if vote_GL!=1


*** REGRESSION MODELS AND DESCRIPTIVE STATISTICS ***

* SOCIAL PRESSURE
tab SozPressur_U
tab SozPressur_LG
tab SozPressur_U_rc
tab SozPressur_LG_rc

* Table 2: Determinants of social pressure
firthlogit SozPressur_LG_rc gender age income education_rc
firthlogit SozPressur_U_rc gender age income education_rc


* ABSTENTION
* Table 3: Determinants of abstention
nbreg notpart_land gender age income education_rc
nbreg notpart_na gender age income education_rc

* CUE-TAKING
tab exposition2_LG
tab exposition2_GV

ttest effic_int, by(exposition2_LG_d)

tab exposition2_LG_d gender, col chi
tab exposition2_LG_d age_cat, col chi

* Table 4: Determinants of cue-taking
ttest effic_int, by(exposition2_LG_d)

logit exposition2_LG_d gender age income education_rc
logit exposition2_LG_d gender age income education_rc effic_int

* BRIDGING AND BONDING
tab SozPressur_talk
tab SozPressur_talk_secret
tab SozPressur_talk_diff
tab SozPressur_talk_same
tab SozPressur_talk_dn

tab SozPressur_talk_opinion
tab SozPressur_talk_opinion SozPressur_talk_secret, col
tab SozPressur_talk_opinion SozPressur_talk_diff, col
tab SozPressur_talk_opinion SozPressur_talk_same, col





*** CREATING WEIGHTS ***
* voting population of Glarus in June 2016
gen n_pop = 26307
gen fpc = n_pop

* Gender
gen gender_type = 13153.5 if gender==1
replace gender_type = 13153.5 if gender==0

* Age 
gen age_type = 3683 if age_cat==1
replace age_type = 4209 if age_cat==2
replace age_type = 3946 if age_cat==3
replace age_type = 4735 if age_cat==4
replace age_type = 4209 if age_cat==5
replace age_type = 5524 if age_cat==6


* Municipality (based on residents entitled to vote in june 2016)
gen municip_type = 7930 if commune==1
replace municip_type = 11351 if commune==2
replace municip_type = 7026 if commune==3

* Education
recode education_rc (3=1) (4/5=2) (6/8=3), gen(educ_cat)
gen educ_type = 4472 if educ_cat==1
replace educ_type = 14995 if educ_cat==2
replace educ_type = 6577 if educ_cat==3



*** APPENDIX ***
gen inmodel_basic_abst_LG=1 if !missing(notpart_land, gender, age, income, education_rc)

* Table A1
tab finish
tab part_la15_d
tab part_GV
tab part_na
tab age_cat
tab income
tab educ_cat
tab commune
recode pol_ideol (0/3=1) (4/6=2) (7/10=3), gen(pol_ideol_cat2)
tab pol_ideol_cat2
tab work
tab party_member
tab public_office_d
mean effic_int
tab pol_int
tab knowledge_GL



* Table A2
tab SozPressur_LG_rc if inmodel_basic_SozPr==1
tab SozPressur_U_rc if inmodel_basic_SozPr==1
tab notpart_land if inmodel_basic_SozPr==1
sum notpart_na if inmodel_basic_SozPr==1, d
tab exposition2_LG_d if inmodel_basic_SozPr==1
tab SozPressur_talk_opinion if inmodel_basic_SozPr==1, m
tab gender if inmodel_basic_SozPr==1
sum age if inmodel_basic_SozPr==1, d
tab commune if inmodel_basic_SozPr==1
tab income if inmodel_basic_SozPr==1
tab education_rc if inmodel_basic_SozPr==1
tab pol_ideol if inmodel_basic_SozPr==1
tab party_member if inmodel_basic_SozPr==1
tab public_office_d if inmodel_basic_SozPr==1
tab pol_int if inmodel_basic_SozPr==1
tab knowledge_GL_rc if inmodel_basic_SozPr==1
sum effic_int if inmodel_basic_SozPr==1, d
tab env_gl if inmodel_basic_SozPr==1

* Table A3
firthlogit SozPressur_LG_rc gender age income education_rc GlarusSud GlarusNord ib2.pol_ideol_cat pol_int knowledge_GL_rc effic_int env_gl party_member public_office_d 
firthlogit SozPressur_U_rc gender age income education_rc GlarusSud GlarusNord ib2.pol_ideol_cat pol_int knowledge_GL_rc effic_int env_gl party_member public_office_d 

* Table A4 
nbreg notpart_land gender age income education_rc GlarusSud GlarusNord ib2.pol_ideol_cat pol_int knowledge_GL_rc effic_int env_gl party_member public_office_d
nbreg notpart_na gender age income education_rc GlarusSud GlarusNord ib2.pol_ideol_cat pol_int knowledge_GL_rc effic_int env_gl party_member public_office_d

* Table A5 
logit exposition2_LG_d gender age income education_rc GlarusSud GlarusNord ib2.pol_ideol_cat pol_int knowledge_GL_rc effic_int env_gl party_member public_office_d

* Table A6 
* Social Pressure (Landsgemeinde)
tab SozPressur_LG

svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)
svy: tab SozPressur_LG
svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)
svy: tab SozPressur_LG
svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)
svy: tab SozPressur_LG
svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)
svy: tab SozPressur_LG

ipfweight gender age_cat commune educ_cat, gen(w_total) val(51 49 14 16 15 18 16 21 31 42 27 17 57 26) maxit(25)
svyset [pw=w_total], fpc(n_pop)
svy: tab SozPressur_LG

* Social Pressure (Ballot)
tab SozPressur_U
svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)
svy: tab SozPressur_U
svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)
svy: tab SozPressur_U
svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)
svy: tab SozPressur_U
svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)
svy: tab SozPressur_U

svyset [pw=w_total], fpc(n_pop)
svy: tab SozPressur_U

* Table A7
* Landsgemeinde
glm notpart_land gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store LG_basic_noweight

svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)
svy: glm notpart_land gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store LG_basic_wgender

svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)
svy: glm notpart_land gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store LG_basic_wage

svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)
svy: glm notpart_land gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store LG_basic_wmunicip

svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)
svy: glm notpart_land gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store LG_basic_weduc

svyset [pw=w_total], fpc(n_pop)
svy: glm notpart_land gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store LG_basic_wtotal


esttab LG_basic_noweight LG_basic_wgender LG_basic_wage LG_basic_wmunicip LG_basic_weduc LG_basic_wtotal, label cells (b(star fmt(3)) se(par fmt(3))) stats(r2 N), using example.rtf, replace



* Ballot Box
glm notpart_na gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store BB_basic_noweight

svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)
svy: glm notpart_na gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store BB_basic_wgender

svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)
svy: glm notpart_na gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store BB_basic_wage

svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)
svy: glm notpart_na gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store BB_basic_wmunicip

svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)
svy: glm notpart_na gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store BB_basic_weduc

svyset [pw=w_total], fpc(n_pop)
svy: glm notpart_na gender age income education_rc, family(nbinomial) link(nbinomial)
estimates store BB_basic_wtotal

esttab BB_basic_noweight BB_basic_wgender BB_basic_wage BB_basic_wmunicip BB_basic_weduc BB_basic_wtotal, label cells (b(star fmt(3)) se(par fmt(3))) stats(r2 N), using example.rtf, replace

* Table A8
tab exposition2_LG
svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)
svy: tab exposition2_LG
svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)
svy: tab exposition2_LG
svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)
svy: tab exposition2_LG
svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)
svy: tab exposition2_LG

svyset [pw=w_total], fpc(n_pop)
svy: tab exposition2_LG

* Table A9
* Cue-taking models
glm exposition2_LG_d gender age income education_rc, family(binomial) link(logit)
estimates store LG_cue_noweight
* Gender 
svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)

svy: glm exposition2_LG_d gender age income education_rc, family(binomial) link(logit)
estimates store LG_cue_wgender

* Age
svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)

svy: glm exposition2_LG_d gender age income education_rc, family(binomial) link(logit)
estimates store LG_cue_wage

* Municipality
svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)

svy: glm exposition2_LG_d gender age income education_rc, family(binomial) link(logit)
estimates store LG_cue_wmunicip

* Education
svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)

svy: glm exposition2_LG_d gender age income education_rc, family(binomial) link(logit)
estimates store LG_cue_weduc

* Total
svyset [pw=w_total], fpc(n_pop)
svy: glm exposition2_LG_d gender age income education_rc, family(binomial) link(logit)
estimates store LG_cue_wtotal

esttab LG_cue_noweight LG_cue_wgender LG_cue_wage LG_cue_wmunicip LG_cue_weduc LG_cue_wtotal, label cells (b(star fmt(3)) se(par fmt(3))) stats(r2 N), using example.rtf, replace



* Table A10
tab SozPressur_talk_opinion SozPressur_talk_secret, col

svyset _n, fpc(n_pop) poststrata(gender) postweight(gender_type)
svy: tab SozPressur_talk_opinion SozPressur_talk_secret, col
svyset _n, fpc(n_pop) poststrata(age_cat) postweight(age_type)
svy: tab SozPressur_talk_opinion SozPressur_talk_secret, col
svyset _n, fpc(n_pop) poststrata(commune) postweight(municip_type)
svy: tab SozPressur_talk_opinion SozPressur_talk_secret, col
svyset _n, fpc(n_pop) poststrata(educ_cat) postweight(educ_type)
svy: tab SozPressur_talk_opinion SozPressur_talk_secret, col

svyset [pw=w_total], fpc(n_pop)
svy: tab SozPressur_talk_opinion SozPressur_talk_secret, col

* Table A11
recode age (15/34=0) (35/100=1), gen(age35)
ranksum Q112_socialize, by(gender)
ranksum Q112_socialize, by(age35)

mean Q112_socialize, over(gender)
mean Q112_socialize, over(age35)

tab Q112_socialize gender, col
tab Q112_socialize age35, col
